package com.ss.android.download;

import android.annotation.TargetApi;
import android.os.Handler;
import android.os.Message;
import android.os.Process;
import android.util.Log;

import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;

final class m implements Handler.Callback {
    private final DownloadService a;

    m(DownloadService arg1) {
        this.a = arg1;

    }

    @TargetApi(value = 5)
    public final boolean handleMessage(Message arg9) {
        boolean v3;
        int v7 = 2;
        Process.setThreadPriority(10);
        int v2 = arg9.arg1;
        Map v1 = this.a.c;
        synchronized (v1) {
            v3 = this.a.b();
        }

        if (arg9.what == v7) {
            Iterator v4 = Thread.getAllStackTraces().entrySet().iterator();
            while (v4.hasNext()) {
                Object v1_1 = v4.next();
                if (!((Thread) ((Map.Entry) v1_1).getKey()).getName().startsWith("pool")) {
                    continue;
                }

                Log.d("SsDownloadManager", ((Map.Entry) v1_1).getKey() + ": " + Arrays.toString(((Object[]) ((Map.Entry) v1_1).getValue())));
            }

            this.a.b.b();
            Log.w("SsDownloadManager", "Final update pass triggered, isActive=" + v3 + "; someone didn\'t update correctly.");
        }

        if (v3) {
            DownloadService v0_1 = this.a;
            v0_1.g.removeMessages(v7);
            v0_1.g.sendMessageDelayed(v0_1.g.obtainMessage(v7, v0_1.h, -1), 300000);
        } else if (this.a.stopSelfResult(v2)) {
            if (this.a.a != null) {
                this.a.getContentResolver().unregisterContentObserver(this.a.a);
            }

            if (this.a.e != null) {
                this.a.e.a.disconnect();
            }

            if (this.a.f != null) {
                this.a.f.quit();
            }

            this.a.d.shutdown();
        }

        return true;
    }
}

